package cn.rkylin.oms.aftersale.sysrefund.utils;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.rkylin.oms.aftersale.sysrefund.servcie.impl.SysRefundServiceImpl;
import cn.rkylin.oms.aftersale.sysrefund.vo.SysRefundVO;
import cn.rkylin.oms.common.consts.ECRefundStatusConsts;
import cn.rkylin.oms.common.consts.SysRefundStatusConsts;
import cn.rkylin.oms.common.consts.YesNoConst;

/**
 * 类名: QueryStatusParam <br/>
 * 已申请退货的hasApplyReturn：平台退款状态为已申请退货，等待卖家同意的系统退款单.<br/>
 * 待买家操作的waitCustomerOper：平台退款状态为卖家已同意等待买家退货，或者卖家拒绝退款的系统退款单.<br/>
 * 待审核的waitingAuth：平台退款状态为买家已退货等待卖家退款、或已申请退款等待卖家退款，且系统退款单状态为未审核的系统退款单<br/>
 * 待退款的waitingRefund：平台退款状态为买家已退货等待卖家退款、或已申请退款等待卖家退款，且系统退款单状态为已审核的系统退款单<br/>
 * 已完成的complete：平台退款状态为退款成功的系统退款单.<br/>
 * 已废弃的cancel：平台退款状态为关闭的系统退款单.<br/>
 * date: 2017年10月22日 上午11:50:51 <br/>
 *
 * @author zhanghao
 * @version 1.0
 */
public class QueryStatusParam {
    private static final Log logger = LogFactory.getLog(SysRefundServiceImpl.class);
    private static Map<String, Method> maps;
    static {
        maps = new HashMap<String, Method>();
        try {
            maps.put("hasApplyReturn", new QueryStatusParam().getClass().getMethod("hasApplyReturn",
                    Class.forName("cn.rkylin.oms.aftersale.sysrefund.vo.SysRefundVO")));
            maps.put("waitCustomerOper", new QueryStatusParam().getClass().getMethod("waitCustomerOper",
                    Class.forName("cn.rkylin.oms.aftersale.sysrefund.vo.SysRefundVO")));
            maps.put("waitingAuth", new QueryStatusParam().getClass().getMethod("waitingAuth",
                    Class.forName("cn.rkylin.oms.aftersale.sysrefund.vo.SysRefundVO")));
            maps.put("waitingRefund", new QueryStatusParam().getClass().getMethod("waitingRefund",
                    Class.forName("cn.rkylin.oms.aftersale.sysrefund.vo.SysRefundVO")));
            maps.put("cancel",
                    new QueryStatusParam().getClass().getMethod("cancel", Class.forName("cn.rkylin.oms.aftersale.sysrefund.vo.SysRefundVO")));
            maps.put("complete",
                    new QueryStatusParam().getClass().getMethod("complete", Class.forName("cn.rkylin.oms.aftersale.sysrefund.vo.SysRefundVO")));
        } catch (Exception e) {
            logger.error(e.getMessage());
            ;
        }
    }

    public static Map<String, Method> getMaps() {
        return maps;
    }

    public QueryStatusParam() {

    }

    /**
     * hasApplyReturn:申请退货tab页的状态设置. <br/>
     * 说明：此状态要求平台退款单的状态为EC_WAIT_SELLER_AGREE，同时退款单有退货诉求.<br/>
     *
     * @author zhanghao
     * @param queryParamVO
     * @return
     */
    public static SysRefundVO hasApplyReturn(SysRefundVO queryParamVO) {
        List<String> refundStatus = new ArrayList<String>();
        if (refundStatus.add(ECRefundStatusConsts.EC_WAIT_SELLER_AGREE)) {
            queryParamVO.setQueryECStatus(refundStatus);
            queryParamVO.setIsAutoCreate(YesNoConst.YES);
        }

        List<String> refundSysStatus = new ArrayList<String>();
        if (refundSysStatus.add(SysRefundStatusConsts.REFUND_APPLIED)) {
            queryParamVO.setQuerySysStatus(refundSysStatus); // 已申请退货
        }
        return queryParamVO;
    }

    public static SysRefundVO waitCustomerOper(SysRefundVO queryParamVO) {
        List<String> refundStatus = new ArrayList<String>();
        if (refundStatus.add(ECRefundStatusConsts.EC_WAIT_BUYER_RETURN_GOODS) && refundStatus.add(ECRefundStatusConsts.EC_SELLER_REFUSE_BUYER)) {
            queryParamVO.setQueryECStatus(refundStatus);
            queryParamVO.setIsAutoCreate(YesNoConst.YES);
        }
        return queryParamVO;
    }

    /**
     * waitingAuth:待审核页面的状态设置. <br/>
     * 说明：此状态要求平台退款单状态为EC_WAIT_SELLER_CONFIRM_GOODS（此状态下退款单肯定有退货诉求）<br/>
     * 或者平台退款单状态为EC_WAIT_SELLER_AGREE但此状态下退款单没有退货诉求.<br/>
     * 
     * 关于是否有退货诉求的限制，体现在SQL上了，代码上不显示，要注意。
     *
     * @author zhanghao
     * @param queryParamVO
     * @return
     */
    public static SysRefundVO waitingAuth(SysRefundVO queryParamVO) {
        List<String> refundEcStatus = new ArrayList<String>();
        if (refundEcStatus.add(ECRefundStatusConsts.EC_WAIT_SELLER_AGREE)
                && refundEcStatus.add(ECRefundStatusConsts.EC_WAIT_SELLER_CONFIRM_GOODS)) {
            queryParamVO.setQueryECStatus(refundEcStatus);
        }
        List<String> refundSysStatus = new ArrayList<String>();
        if (refundSysStatus.add(SysRefundStatusConsts.REGISTER)) {
            queryParamVO.setQuerySysStatus(refundSysStatus);
        }
        return queryParamVO;
    }

    public static SysRefundVO waitingRefund(SysRefundVO queryParamVO) {

        List<String> refundEcStatus = new ArrayList<String>();
        if (refundEcStatus.add(ECRefundStatusConsts.EC_WAIT_SELLER_AGREE)
                && refundEcStatus.add(ECRefundStatusConsts.EC_WAIT_SELLER_CONFIRM_GOODS)) {
            queryParamVO.setQueryECStatus(refundEcStatus);
        }
        List<String> refundSysStatus = new ArrayList<String>();
        if (refundSysStatus.add(SysRefundStatusConsts.AUTHENTICATED)) {
            queryParamVO.setQuerySysStatus(refundSysStatus);
        }
        return queryParamVO;
    }

    public static SysRefundVO complete(SysRefundVO queryParamVO) {
        List<String> refundStatus = new ArrayList<String>();
        if (refundStatus.add(SysRefundStatusConsts.REFUNDED)) {
            queryParamVO.setQuerySysStatus(refundStatus);
        }
        return queryParamVO;
    }

    public static SysRefundVO cancel(SysRefundVO queryParamVO) {
        List<String> refundStatus = new ArrayList<String>();
        if (refundStatus.add(SysRefundStatusConsts.CLOSED)) {
            queryParamVO.setQuerySysStatus(refundStatus);
        }
        return queryParamVO;
    }
}
